;(function () {
    'use strict';
    angular.module('common',[])
        .service('TimelineService',[
            '$http',
            function ($http) {
                var me = this
                me.data = [];
                me.page = 1;

                this.get = function (conf) {
                    if (me.pending) return;
                    me.pending = true;

                    conf = conf || {page:me.page,limit:16};
                    $http.post('/api/timeline',conf)
                        .then(function (r) {
                            if (r.data.status){
                                if (r.data.data.length){
                                    me.data = me.data.concat(r.data.data);
                                    me.page++;
                                } else{
                                    me.no_more_data = true;
                                }
                            }else {
                                console.error('network error');
                            }

                        },function () {
                            console.error('network error');
                        })
                        .finally(function () {
                            me.pending = false;
                        })
                }
            }
        ])
})();